123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- "use client";
- import { DepositsTypes } from "@/api/depositsApi";
- import { getUserRechargeApi } from "@/api/user";
- import Box from "@/components/Box";
- import { useUserInfoStore } from "@/stores/useUserInfoStore";
- import { neReg } from "@/utils";
- import { Form, Input, Toast } from "antd-mobile";
- import { FormInstance } from "antd-mobile/es/components/form";
- import { useTranslations } from "next-intl";
- import { FC, Fragment, useRef, useState } from "react";
- import ButtonOwn from "@/components/ButtonOwn";
- import "@/styles/deposit.scss";
- import { Autoplay, Pagination } from "swiper/modules";
- import { Swiper, SwiperSlide } from "swiper/react";
- interface Props {
- deposits: DepositsTypes[];
- }
- const DepositData: FC<Props> = (props) => {
- const { deposits } = props;
- const t = useTranslations();
- const userInfo = useUserInfoStore((state) => state.userInfo);
- // 选中类型
- const [activeType, setActiveType] = useState<DepositsTypes>(deposits[0]);
- // 是否自定义充值
- const [isCustomInput, setIsCustomInput] = useState(false);
- const formInstanceRef = useRef<FormInstance>(null);
- let [amount, setAmount] = useState<number | undefined>(undefined);
- const titleChangeHandler = (item: DepositsTypes, index: number) => {
- setAmount(undefined);
- setActiveType(item);
- formInstanceRef.current?.resetFields();
- };
- const isStrictMode = true;
- const onFinish = (values: any) => {
- const params = { ...values, channel_id: activeType.id, amount: +values.amount };
- getUserRechargeApi(params)
- .then((res) => {
- formInstanceRef.current?.resetFields();
- Toast.show({ icon: "success", content: t("code.200"), maskClickable: false });
- setAmount(undefined);
- if (res.data.pay_url) {
- window.open(res.data.pay_url);
- }
- })
- .catch((error) => {
- Toast.show({ content: t(`code${error.data.code}`), maskClickable: false });
- });
- };
- const onValuesChange = (changeValues: any) => {
- if (changeValues.amount) {
- setAmount(changeValues.amount);
- }
- };
- const amountChange = (value: number) => {
- formInstanceRef.current?.setFieldValue("amount", value);
- setAmount(value);
- };
- const amountValidator = (rules: any, value: any) => {
- if (!value) return Promise.reject(new Error(t("form.amount")));
- if (+value < activeType.min_amount)
- return Promise.reject(
- new Error(t("form.amountMinReg", { amount: activeType.min_amount }))
- );
- if (+value > activeType.max_amount)
- return Promise.reject(
- new Error(t("form.amountMaxReg", { amount: activeType.max_amount }))
- );
- return Promise.resolve();
- };
- const banners = [
- {
- id: 61,
- sort: 0,
- show_platform: 1,
- action_type: 1,
- action_params: "",
- content: "http://192.168.0.237:9000/bcwin/86fa3351-2aef-4ede-ba70-cae365f03812.jpg",
- },
- {
- id: 62,
- sort: 0,
- show_platform: 1,
- action_type: 1,
- action_params: "",
- content: "http://192.168.0.237:9000/bcwin/9809de49-966e-4dea-81c9-baa71347dc6c.jpg",
- },
- ];
- return (
- <>
- <div style={{ height: "1.86rem" }} className={"home-banner"}>
- <Swiper
- autoplay={{ delay: 2500 }}
- pagination={{ clickable: true }}
- spaceBetween={10}
- scrollbar={{ draggable: true }}
- slidesPerView={1}
- loop
- modules={[Pagination, Autoplay]}
- >
- {banners.map((banner, index) => (
- <SwiperSlide key={index}>
- <Box
- none
- action={banner.action_type as 1}
- actionData={banner.action_params}
- >
- <img
- src={banner.content}
- style={{ height: "1.86rem", width: "100%" }}
- alt={"banner"}
- />
- </Box>
- </SwiperSlide>
- ))}
- </Swiper>
- </div>
- <div className="deposit-box">
- <p>title</p>
- <p className={"text-[0.12rem] text-[#e8e8e8]"}>
- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab accusamus amet
- animi beatae blanditiis cumque dicta dolor eius est ex, facilis illo libero
- magnam placeat quibusdam similique ullam, vel veniam?
- </p>
- <div className={"flex flex-wrap"}>
- {deposits.map((item, index) => {
- return (
- <Fragment key={item.id}>
- <p
- className="btn-box truncate"
- style={{
- borderColor: activeType.id === item.id ? "#ff9323" : "#333",
- }}
- onClick={() => titleChangeHandler(item, index)}
- >
- {item.name}
- </p>
- </Fragment>
- );
- })}
- </div>
- <Box className={"custom-form"} style={{ padding: 0 }}>
- <Form
- style={{
- "--border-bottom": "none",
- "--border-top": "none",
- "--border-inner": "none",
- }}
- ref={formInstanceRef}
- initialValues={userInfo}
- onFinish={onFinish}
- onValuesChange={onValuesChange}
- >
- {isStrictMode ? (
- <>
- <Form.Item
- name="user_name"
- label=""
- rules={[{ required: true, message: t("form.usernameReg") }]}
- >
- <Input placeholder={t("form.username")} />
- </Form.Item>
- <Form.Item
- name="passport"
- label=""
- rules={[
- {
- required: true,
- message: t("form.cardReg"),
- pattern: neReg,
- },
- ]}
- >
- <Input
- placeholder={t("form.card")}
- maxLength={11}
- type={"text"}
- />
- </Form.Item>
- </>
- ) : null}
- {isCustomInput && (
- <Form.Item
- name="amount"
- label=""
- rules={[
- { required: true, type: "number", validator: amountValidator },
- ]}
- >
- <Input
- placeholder={`${t("DepositPage.Montante")}(BRL): Mín. ${activeType.min_amount}`}
- type={"number"}
- maxLength={activeType.max_amount}
- />
- </Form.Item>
- )}
- <div className={"flex flex-col"}>
- <div className={"flex-1"}>
- <ul className="ul-box">
- {activeType.products.map((item, index) => (
- <li
- className={amount == item.amount ? "active" : ""}
- key={index}
- onClick={() => amountChange(item.amount)}
- >
- {!!item.badge && <span className="hot"></span>}
- <div className="amountContent">
- {/* <span className="iconfont icon-unit-brl"></span> */}
- <span className="iconfont">R$</span>
- <span> {item.amount}</span>
- </div>
- <span className="amountTips">
- {t("DepositPage.Oferecer")} 100%
- </span>
- </li>
- ))}
- </ul>
- </div>
- </div>
- </Form>
- </Box>
- <ButtonOwn
- style={{ marginTop: "0.1389rem" }}
- active
- callbackFun={() => setIsCustomInput(true)}
- >
- {t("DepositPage.customButtonText")}
- </ButtonOwn>
- </div>
- </>
- );
- };
- export default DepositData;
|